//
//  BalanceDetaileViewController.m
//  renxinghuan
//
//  Created by 王晓民 on 2018/4/28.
//  Copyright © 2018年 吴清翠. All rights reserved.
//

#import "BalanceDetaileViewController.h"
#import "configuration.h"
#import "BalanceDetailMode.h"
#import "BalanceTableViewCell.h"
@interface BalanceDetaileViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation BalanceDetaileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadmyProfit];
    [self setupNavButton];
    
    //表视图
    [self setupTableView];
    //数组初始化
    self.dataArray = [[NSMutableArray alloc] init];}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)ObtainButton{
    
    UILabel * label = [[UILabel alloc] init];
    label.text = @"暂无消息";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:MiddleFont];
    label.frame = CGRectMake(0, ScreenHeight/2, ScreenWidth, 60);
    label.textColor = WYCRGBColor(200, 200, 200);
    [self.view  addSubview:label];
}
//表视图
- (void)setupTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavHeight, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = WYCGlobalBg;
    
    [self.view addSubview:self.tableView];
    
}

//Nav按钮及颜色
- (void)setupNavButton{
    self.navigationItem.title = @"收支明细";
    self.view.backgroundColor = WYCGlobalBg;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:wycMain];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 250 * px;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * strID = @"cell";
    
    BalanceTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:strID];
    
    if (cell == nil)
    {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"BalanceTableViewCell" owner:self options:nil]lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    BalanceDetailMode * DetailModel = self.dataArray[indexPath.row];

    
    cell.timeLb.text = DetailModel.createTime;
    NSString *type = DetailModel.type;
    cell.moneyLb.text =[NSString stringWithFormat:@"%.1f",[DetailModel.amount doubleValue]];

    if ([type isEqualToString:@"1"])
    {
        cell.BalanceLb.text = @"收入";

    }
    else
    {
        cell.BalanceLb.text = @"提现";


    }
    return cell;
}

-(void)loadmyProfit
{
    
    
    [HttpTool POST:myProfitDetails params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSLog(@"收支明细%@",responseObject);
        
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            
            NSArray * detaeilArray = responseObject[@"result"];
            for (NSDictionary * dic in detaeilArray)
            {

                BalanceDetailMode * DetailModel = [BalanceDetailMode mj_objectWithKeyValues:dic];

                [self.dataArray addObject:DetailModel];
            }
            
        }
        [self.tableView reloadData];
        
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}




@end
